<!--登录页面-->
<template>
  <div class="login-container">
    <!--用戶登錄-->
    <div v-if="showloginForm">
      <Form
        ref="loginForm"
        :model="loginForm"
        class="login-form"
        autocomplete="on"
        label-position="left"
      >
        <FormItem prop="phone">
          <span class="svg-container">
            <i class="el-icon-user-solid"></i>
          </span>
          <Input
            ref="phone"
            v-model="loginForm.operatorName"
            placeholder="请输入用户名"
            name="username"
            type="tell"
            tabindex="1"
            autocomplete="on"
          ></Input>
        </FormItem>

        <!--密码框登录-->
        <div>
          <Tooltip
            v-model="capsTooltip"
            content="Caps lock is On"
            placement="right"
            manual
          >
            <FormItem prop="password">
              <span class="svg-container">
                <i class="el-icon-lock"></i>
              </span>
              <Input
                ref="password"
                :key="passwordType"
                v-model="loginForm.operatorPwd"
                :type="passwordType"
                placeholder="请输入密码"
                name="password"
                tabindex="2"
                autocomplete="on"
                @keyup.enter.native="handleLogin"
              />
            </FormItem>
          </Tooltip>
          <Button
            :loading="loading"
            type="primary"
            size="min"
            style="width: 100%; margin-bottom: 30px; margin-top: 10px"
            @click.native.prevent="handleLogin"
            >登录
          </Button>
        </div>
      </Form>
    </div>
  </div>
</template>

<script>
import { setLocalStorage } from "@/utils/index.js";
import { validCode, validPassword, validPhone } from "@/utils/validate";
import { Form, FormItem, Button, Tooltip, Input } from "element-ui";
export default {
  props: {},
  components: {
    Form,
    FormItem,
    Button,
    Tooltip,
    Input,
  },
  data() {
    const validatePhone = (rule, value, callback) => {
      const is_true = validPhone(value);
      if (is_true == true) {
        callback();
      } else {
        callback(new Error(is_true));
      }
    };
    const validatePassword = (rule, value, callback) => {
      const is_true = validPassword(value);
      if (is_true == true) {
        callback();
      } else {
        callback(new Error(is_true));
      }
    };

    const validateCode = (rule, value, callback) => {
      const is_true = validCode(value);
      if (is_true == true) {
        callback();
      } else {
        callback(new Error(is_true));
      }
    };
    return {
      //用户协议
      openProtocol: false,
      checkbox: true,

      cur: true, //true代表密码, false代表短信
      sendButtonText: "获取验证码",
      sendDisabled: false,
      //是否显示微信登录图片
      showWeixin: true,
      //微信登录弹窗
      Qrcode: false,
      //随机数
      state: "",
      //微信回调接口
      // redirect_uri:encodeURIComponent(this.pc_url+'/wxLogin?redirect='+encodeURIComponent(this.$route.query.redirect)),

      //用户登录
      showloginForm: true,
      //忘记密码
      showForgetPwd: false,
      loginForm: {
        operatorName: "",
        operatorPwd: "",
      },

      // loginRules: {
      //   phone: [{ required: true, trigger: "blur", validator: validatePhone }],
      //   password: [
      //     { required: true, trigger: "blur", validator: validatePassword },
      //   ],
      //   code: [{ required: true, trigger: "blur", validator: validateCode }],
      // },

      ForgetPwdRules: {
        ForgetPhone: [
          { required: true, trigger: "blur", validator: validatePhone },
        ],
        password: [
          { required: true, trigger: "blur", validator: validatePassword },
        ],
        password1: [
          { required: true, trigger: "blur", validator: validatePassword },
        ],
        code: [{ required: true, trigger: "blur", validator: validateCode }],
      },

      passwordType: "password",
      capsTooltip: false,
      loading: false,
      redirect: undefined,
      otherQuery: {},
    };
  },

  created() {},

  mounted() {
    // this.handleLogin();
  },

  methods: {
    inputPhone(val) {
      console.log(val);
      this.loginForm.phone = val;
    },
    userProtocol() {},
    //用户登录
    handleLogin() {
      console.log(this.loginForm);
      this.toHome()
      this.$axios.get(`${this.$api.user.login}?operatorName=1&operatorPwd=1`).then((res) => {
        console.log(this.loginForm);
      });
    },
    //查询菜单
    queryPerms() {
      this.$axios.get(this.$api.user.queryPerms, {}).then((res) => {
        console.log(res);
      });
    },
    toHome() {
      let userInfo = {
        rules: 1,
        userNmae: "123456",
        token: "iqwyiyriqyewr123",
      };
      //存储用户信息
      setLocalStorage("userInfo", userInfo);
      this.$store.dispatch("ADD_USER_INFO", userInfo);
      this.$router.push("/");
    },
    //显示密码
    showPwd() {
      if (this.passwordType === "password") {
        this.passwordType = "";
      } else {
        this.passwordType = "password";
      }
      this.$nextTick(() => {
        this.$refs.password.focus();
      });
    },
  },

  computed: {},

  watch: {},
};
</script>
<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg: #283443;
$light_gray: #333;
$cursor: #333;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    // height: 47px;
    width: 85%;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      // padding: 12px 5px 12px 15px;
      // color: $light_gray;
      // height: 47px;
      // caret-color: $cursor;

      // &:-webkit-autofill {
      //   box-shadow: 0 0 0px 1000px $bg inset !important;
      //   -webkit-text-fill-color: $cursor !important;
      // }
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 1);
    border-radius: 5px;
    color: #454545;
  }
}
</style>

<style lang="scss" scoped>
$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;

.weixinlogo {
  display: block;
  margin: 0 auto;
  width: 50px;
}

.register_hint {
  text-align: center;
  color: white;
}

.login-container {
  min-height: 100%;
  width: 100%;
  // background-color: $bg;
  background: url("~@/assets/img/loginBg.jpg") no-repeat center;
  background-size: 100%;
  overflow: hidden;

  .login-form {
    position: relative;
    width: 520px;
    max-width: 100%;
    padding: 160px 35px 0;
    margin: 0 auto;
    overflow: hidden;
  }

  .tips {
    font-size: 14px;
    color: #333;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      font-size: 26px;
      color: $light_gray;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }

  .thirdparty-button {
    position: absolute;
    right: 0;
    bottom: 6px;
  }

  @media only screen and (max-width: 470px) {
    .thirdparty-button {
      display: none;
    }
  }
}

.a {
  color: #fff;
  margin: 30px;
}

.login_header {
  margin-bottom: 30px;
  text-align: center;
}

.login_header span {
  margin-right: 20px;
  cursor: pointer;
}

.Cbody_item {
  border: 0px solid #999;
  overflow: hidden;
}

.active {
  color: #fff;
  padding-bottom: 10px;
  border-bottom: 3px solid #fff;
}
</style>
